﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yu.Cms.Common;

namespace Yu.Cms.Web.UserCtrl.Admin
{
    public partial class AlbumDel : BaseCtrl
    {
        protected void Page_Load(object sender, EventArgs e)
        {          
            int intBigID = YuRequest.GetQueryInt("bigid", 0);
            string Act = YuRequest.GetQueryString("act");
           
            if (!IsPostBack)
            {
                if (Act.ToLower() == "del")
                {
                    int iCount = bllalbum.GetCountByBigID(intBigID);
                    if (iCount != 0)
                    {
                        lblShow.Text = "相册中有" + iCount + "张照片";
                        lblInfo.Text = " <h1> 相册删除后将无法恢复，在日志使用的照片也将删除。</h1>";
                        Hid.Value = intBigID.ToString();
                    }
                    else
                    {
                        bllalbumType.Delete(intBigID);  //直接删除相册
                        Response.Write(" <script>alert('删除成功');tb_remove();window.location = 'Album.aspx';</script>");
                        Response.End();
                    }
                }
                else if (Act.ToLower() == "delok")
                {
                    int alBigID = YuRequest.GetFormInt("bigid", 0);
                    int rInt1 = 0;
                    int rInt2 = 0;
                    int rInt = 0;
                    rInt1= bllalbum.DelByeBigID(alBigID); //删除
                    rInt2 =bllalbumType.Delete(alBigID);  //删除
                    if (rInt1 != 0 && rInt2 != 0)
                    {
                       rInt = rInt1;                       
                       this.DeletByBigID(alBigID);
                    }                   
                    Response.Write(rInt);
                    Response.End();
                    //删除
                }
            }
        }

        /// <summary>
        /// 删除图片文件
        /// </summary>
        /// <param name="alBigID"></param>
        protected void DeletByBigID(int alBigID)
        {
            int RecordCount;
            IList<Yu.Cms.Model.album> lst=bllalbum.GetListByBigID(alBigID, out RecordCount);
            if (lst.Count > 0)
            {
                for (int i=0; i < lst.Count; i++)
                {
                    try
                    {
                        string sfilePath = Utils.GetRootPath(); //文件路径   
                        FSO.Delete(sfilePath + lst[i].alPath, FsoMethod.File);
                        FSO.Delete(sfilePath + lst[i].alThumbPath, FsoMethod.File);
                    }
                    catch
                    {
                        //删除，不抛出异常
                    }
                }
            }
        }
    }
}